<php>
	$this->display(tpl('head',true)); 
	if($edit['bold']){
		$bold='checked';
	}
	if($nid>1){
		$display="style='display:none'";
	}
	$is_comment[$edit['is_comment']] ='checked';
</php>
<style>
	.layui-form-select{
		width: 30%;
	}
	.special{
		width: 200px;
	}
</style>
<script src="/public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>添加文章</legend>
</fieldset>
<form class="layui-form" method="post" action="">
	<div class="layui-tab">
		<ul class="layui-tab-title" $display>
			<li class="layui-this">网站设置</li>
			<li>模型</li>
			<li>专题设置</li>
			<li>其它</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<table class="layui-table my-tabel">
					<tbody>
						<tr>
							<td>所属栏目</td>
							<td>
								<select name="post[cid]" lay-filter="ciddb" class=" my-input">
		    						<option value="">请选择要发布到的栏目</option>
									<foreach array="allcidDB">
									<php>
										$selected=$row['cid']===$cid ? "selected" : "";
										$dis=$row['type'] !==0 ? "disabled" :"";
									</php>
									<option value="{{$row['cid']}}" type="{{$row['type']}}"  mid="{{$row['cmid']}}" {{$selected}}{{$dis}}>{{$row['levels'] }}{{$row['name']}}</option>
									</foreach>
			    				</select>
							</td>
						</tr>
						<tr>
							<td>标题</td>
							<td>
								<input name="post[title]" value="{{$edit['title']}}"  lay-verify="title" placeholder="请输入标题" class="layui-input my-input" type="text">
								颜色
								<input name="post[color]" id="color" class="layui-input my-input color" type="text" value="{{$edit['color']}}">
								<input name="post[bold]" title="加粗" type="checkbox" value="1" {{$bold}}>
								<div id="picker"></div>
				    			<script type="text/javascript">
				    				$("#color").css('background-color','#{{$edit['color']}}');
				    				$("#color").css('color','#fff');
				    				$('#color').colpick({
										layout:'hex',
										submit:0,
										colorScheme:'dark',
										onChange:function(hsb,hex,rgb,el,bySetColor) {
											$(el).css('border-color','#'+hex);
											$(el).css('color','#FFF');
											$(el).css('background-color','#'+hex);
											if(!bySetColor) $(el).val(hex);
										}
									}).keyup(function(){
										$(this).colpickSetColor(this.value);
									});
				    			</script>
				    			
							</td>
						</tr>
						<tr>
							<td>关键字</td>
							<td>
								<input name="post[keyword]"  class="layui-input my-input" type="text" value="{{$edit['keyword']}}">
								<p>作为相关文章的索引,如多个用空格隔开</p>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<table class="layui-table my-tabel">
									<tbody>
										<tr>
											<td>作者</td>
											<td><input name="post[author]" class="layui-input" type="text" value="{{$edit['author']}}"></td>
											<td>来源</td>
											<td><input name="post[source]" class="layui-input" type="text" value="{{$edit['source']}}"></td>
											<td>来源网址</td>
											<td><input name="post[source_url]" class="layui-input" type="text" value="{{$edit['source_url']}}"></td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<table class="layui-table my-tabel">
									<tbody>
										<tr>
											<td>是否禁止评论</td>
											<td><input name="post[is_comment]" class="layui-input" type="checkbox" value="1" title="勾选禁止评论" {{$is_comment[1]}}></td>
											<td>查看积分</td>
											<td><input name="post[sell_jifen]" class="layui-input" type="text" value="{{$edit['sell_jifen']}}"></td>
											<td>查看密码</td>
											<td><input name="post[password]" class="layui-input" type="text" value="{{$edit['password']}}"></td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
						<tr>
							<td>缩略图</td>
							<td>
								<input name="post[thumb]" id="thumb" class="layui-input  my-input" type="text" value="{{$edit['thumb']}}">
			    				<button type="button" class="layui-btn layui-btn-normal" id="select_pic">选择图片上传</button>
							</td>
						</tr>
						<tr>
							<td>内容</td>
							<td>
								<?php
									$num=count((array)$cont_query);
									if($num >1){
								?>
								<div class="page">
									<?php
										$i=0;
										$num=count((array)$cont_query);
										if($num >1)
										foreach((array)$cont_query AS $row){
											$i++;
									?>
										<a href="javascript:void(0);" onclick="return content('{{$row['nid']}}',this);"> 第{{$i}}页</a>
									<?php } ?>
								</div>
								<script>
									var content_data={{json_encode($cont_query);}};
								</script>
								<?php } ?>
								<p>如果是多页在要分页的地方插入##page##</p>
								<textarea name="post[content]" style="height:300px; width: 100%; z-index: 1;" id="content" placeholder="请输入内容" >{{$cont_query['0']['content']}}</textarea>
								<script type="text/javascript">
									var ue = UE.getEditor('content',{
										zIndex : 900,
										autoHeightEnabled:false,
								        // 服务器统一请求接口路径
								        serverUrl: "/admin/index/plugin/ueditor/index/ueditor_config/",
								        toolbars: [[
								             'source', '|', 'undo', 'redo', '|',
								            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
								            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
								            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
								            'directionalityltr', 'directionalityrtl', 'indent', '|',
								            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
								            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
								            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
								            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
								            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
								            'print', 'preview', 'searchreplace', 'drafts', 'help'
								        ]]});
								</script>
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center">
								<input type="hidden" name="post[aid]" value="{{$edit['aid']}}" />
								<input type="hidden" id="nid" name="post[nid]" value="{{$cont_query['0']['nid']}}" />
								<input type="hidden" name="post[step]" value="post" />
								<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
							</td>
							<script>
								var _this='';
								function content(nid,content,THIS){
									console.log(nid);
									if(_this){
										_this.style.backgroundColor='';
										_this.style.color ='';
										_this.style.fontWeight ='';
									}
									_this=THIS;
									for(var i=0;i<content_data.length;i++){
										if(content_data[i].nid==nid){
											ue.setContent(content_data[i].content);
											$("#nid").val(nid);
										}
									}
									console.log(THIS);
									THIS.style.backgroundColor='red';
									THIS.style.color ='#fff';
									THIS.style.fontWeight ='bold';
								}
								
							</script>
						</tr>
					</tbody>
				</table>
					
			</div>

			<div class="layui-tab-item">
				<table class="layui-table my-tabel">
					<tr>
						<td>所属内容模型</td>
						<td>
							<select name="post[mid]"  lay-filter="middb">
		    				<option value="">不使用模型</option>
							<foreach array="moduleDB">
							<php>
								if($mid){
									$m[$mid]="selected";
								}
							</php>
								<option value="{{$row['id']}}" {{$m[$row['id']]}}>{{$row['name']}}</option>
							</foreach>

		    				</select>
						</td>
					</tr>
				</table>
				<table class="layui-table my-tabel" id="model_content">
					<tr>
						<td>
						{{$Custom_Model_Template}}
						</td>
					</tr>
				</table>
			</div>
			<div class="layui-tab-item">
				<style>
					.special_select input[type="checkbox"]{
						width: 35px;
					}
				</style>
				<table class="layui-table my-tabel special_select">
					<tr>
						<td>所属专题(可多选)</td>
						<td>
							<foreach array="special_list">
							<php>
								$checked=in_array($row['id'],(array)$selected_special_list) ? " checked" : "";
							</php>
							<label><input type="checkbox" lay-ignore name="special[]"  value="{{$row['id']}}" {{$checked}}/>{{$row['name']}}</label>
							</foreach>
						</td>
					</tr>
				</table>
				
			</div>
			<div class="layui-tab-item">
				<table class="layui-table my-tabel">
					<tbody>
						<tr>
							<td>发布时间</td>
							<td><input name="post[posttime]" id="posttime" class="layui-input my-input" type="text" value="{{$edit['posttime']}}"></td>
						</tr>
						<tr>
							<td>访问量</td>
							<td>
								<input name="post[clicks]" class="layui-input my-input" type="text" value="{{$edit['clicks']}}">
							</td>
						</tr>
						<tr>
							<td>简介</td>
							<td>
								<textarea class="layui-textarea  my-input" id="description" name="post[description]">{{$edit['description']}}</textarea>
							</td>
						</tr>
						<tr>
							<td>SEO标题</td>
							<td>
								<input name="post[seotitle]" class="layui-input my-input" type="text" value="{{$edit['seotitle']}}">
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
  	</div>
</div>
</form>
<script>
	layui.config({
		version: '{{NOWTIME}}'
	});
	layui.use(['upload','form','layer','element','laydate'], function(){
	  	var $ = layui.jquery
	  	,element = layui.element
	  	,upload = layui.upload;
	   	var $ = layui.jquery, layer = layui.layer;
		var form = layui.form;
		form.on('select(ciddb)', function(data){
			var type=data.elem.selectedOptions[0].attributes.type.value;
			var mid=data.elem.selectedOptions[0].attributes.mid.value;
			if(type !=0){
				$('.layui-btn').attr("disabled",true);
				alert("只有栏目才可以发布内容，请重新选择");
				return false;
			}else if(data.value > 0){
				<?php if($edit){ ?>
				window.location.href='{{ ADMIN_MODULE_URL }}/articles/edit/cid_'+data.value+'/aid_{{$edit['aid']}}';
				<?php }else{ ?>
					window.location.href='{{ ADMIN_MODULE_URL }}/articles/add/cid_'+data.value;
				<?php } ?>
				$('.layui-btn').attr("disabled",false); 
			}
		});
		var laydate = layui.laydate;
		laydate.render({
			elem: '#posttime',
			type: 'datetime'
		});
		form.verify({
		    title: function(value){
			    if(value.length < 5){
			        return '标题至少得5个字符啊';
			    }
		    }
	  	});
	
		form.on('select(middb)', function(data){
			if(data.value !=0){
				htmlobj=$.ajax({url:"{{ ADMIN_MODULE_URL }}/articles/ajax_Module/mid_"+data.value,async:false});
				$("#model_content").html(htmlobj.responseText);
				form.render();
				return false;
			}
		});
		
		
		//选完文件后不自动上传
		upload.render({
		    elem: '#select_pic',
		    url: '{{ ADMIN_MODULE_URL }}/upfile/up/thumb_1/json_true/',
		    auto: true,
		    bindAction: '#star_upload',
		    before: function(obj){
		    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
		    	loading = layer.load();
		    },
		    done: function(res, index, upload){
		    	layer.close(loading);
			    if(res.code !=0){
			    	layer.msg(res.text);
			    }else{
			      	$('#thumb').val(res.url); 
			    }
			    delete files[index]; //删除对应的文件
		    }
		});
	});	  
</script>

<php> $this->display(tpl('foot',true)); </php>
